---
title: "NYC Restaurant Inspection Dashboard - Pizza Restuarants in 2017"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source_code: embed
---
```{r setup, include=FALSE}
library(tidyverse)
library(p8105.datasets)
library(flexdashboard)
library(plotly)
```
```{r, include = FALSE}
data("rest_inspec")
rest_inspec_df =
rest_inspec %>%
janitor::clean_names() %>%
separate(inspection_date, into = c("inspec_year", "inspec_month", "inspec_day"), sep = "-") %>%
filter(
inspec_year == "2017",
cuisine_description == "Pizza")
```
Column {data-width=600}
-----------------------------------------------------------------------
### Scatter Plot
```{r}
n = rest_inspec_df %>%
subset(boro != "Missing") %>%
group_by(boro) %>%
summarise(no_observations = sum(!is.na(score)))
rest_inspec_df %>%
subset(boro != "Missing") %>%
group_by(boro, inspec_month) %>%
mutate(
mean_score = mean(score, na.rm = TRUE)) %>%
mutate(
n = sum(!is.na(score))) %>%
mutate(
text_label = str_c("Borough: ", boro)) %>%
plot_ly(
x = ~inspec_month, y = ~mean_score, color = ~boro,
type = "scatter", colors = "viridis", size = ~n,
alpha = .5, text = ~text_label) %>%
layout(title = 'Mean Pizza Restaurant Inspection Score by Month and Borough, 2017',
xaxis = list(title = 'Month (Jan - Oct)'),
yaxis = list(title = 'Mean Score'),
legend = list(title = list(text = 'Borough')))
```
Column {data-width=400}
-----------------------------------------------------------------------
### Box Plot
```{r}
rest_inspec_df %>%
subset(boro != "Missing") %>%
group_by(boro) %>%
plot_ly(
y = ~score,
color = ~boro,
type = "box",
colors = "viridis",
alpha = .5) %>%
layout(title = 'Boxplots of Pizza Restaurant Inspection Scores by Borough, 2017',
xaxis = list(title = 'Borough'),
yaxis = list(title = 'Restaurant Inspection Score'),
legend = list(title = list(text = 'Borough')))
```
### Bar Plot
```{r}
rest_inspec_df %>%
subset(boro != "Missing") %>%
subset(critical_flag != "Not Applicable") %>%
group_by(boro) %>%
count(critical_flag) %>%
mutate(boro = fct_reorder(boro, n)) %>%
plot_ly(
x = ~critical_flag, y = ~n, color = ~boro,
type = "bar", colors = "viridis",
alpha = .8) %>%
layout(title = 'Pizza Restuarant Inspection Status and Borough, 2017',
xaxis = list(title = 'Inspection Status'),
yaxis = list(title = 'Inspection Count'),
legend = list(title = list(text = 'Borough')))
```